<template>
  <div class="container">
      <ul>
        <li class="headImg" @click="selectImg">
          <span class="title">头像</span>
          <img src="http://file.rzkeji.com/web/daka/icon/icon-next-set.png" class="goImg goHeadImg" />
          <img :src="information.headImg" :id="information.returnId"class="peopleImg"/>
        </li>
        <li class="headImg" @click="go('name')">
          <span class="title">名字</span>
          <span class="rightName">
              {{information.nickname}}
              <img src="http://file.rzkeji.com/web/daka/icon/icon-next-set.png" class="goImg" /></span>
        </li>
        <li class="headImg" @click="go('number')">
          <span class="title">微信号</span>
          <span class="rightName">
              {{information.weChatNumber}}
              <img src="http://file.rzkeji.com/web/daka/icon/icon-next-set.png" class="goImg" /></span>
        </li>
        <li class="headImg">
          <span class="title">出生日期</span>
          <picker mode="date" :value="information.birthDate" start="1970-01-01" end="2030-01-01" @change="bindDateChange" class="pikcker">
             <div class="picker">
               {{information.birthDate}}
               <img src="http://file.rzkeji.com/web/daka/icon/icon-next-set.png" class="goImg"/>
             </div>
          </picker>
        </li>
        <li class="headImg">
          <span class="title">性别</span>
          <picker @change="bindPickerChange" :value="index" :range="array" class="pikcker">
          <view class="picker">
              {{array[information.index]}}
              <img src="http://file.rzkeji.com/web/daka/icon/icon-next-set.png" class="goImg" />
          </view>
          </picker>
        </li>
        <li class="headImg" @click="go('sign')">
          <span class="title" >个性签名</span>
          <img src="http://file.rzkeji.com/web/daka/icon/icon-next-set.png" class="goImg goSign" />
          <span class="rightName">
            {{information.sign}}
          </span>
        </li>
      </ul>
  </div>
</template>
<script>
export default {
  data () {
    return {
      array:['男','女'],
      headImg:""
  }
 },
  methods: {
    go(value){
       wx.navigateTo({
        url:"../inputInformation/main?id="+value
       })
    },
    bindDateChange(e){
       this.information.birthDate=e.target.value;
    },
    bindPickerChange(e){
       this.information.index=e.target.value;
    },
    dateFormat(value){   //这里是把日期转化成YYYY-MM-DD  //这里传入的日期是new Date()后的
       var todayMonth=value.getMonth() +1<10 ? "0" +(value.getMonth()+1) : (value.getMonth()+1);
      var todayDay=value.getDate() <10 ? "0"+value.getDate() : value.getDate();
      var today=value.getFullYear()+"-"+todayMonth+"-"+todayDay;
      return today;
     },
    selectImg(){
        var _this=this;
        wx.chooseImage({
        count: 1,   //规定可选的照片数量
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res){
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths;
        var userToken=wx.getStorageSync('userToken');
        wx.uploadFile({
          url:"https://daka.rzkeji.com/api/file/upload-user-photo",
          filePath:tempFilePaths[0],
          name:"photo",
          formData:{
            daka_token:userToken
          },
          header: {
          'content-type': 'application/json' // 默认值
          },
          success(res){
            _this.headImg=tempFilePaths[0];
            _this.information.returnId=JSON.parse(res.data).data;
             _this.information.headImg=tempFilePaths[0];
            _this.$store.dispatch('setInformation',_this.information);
          }
        })
        }
      })
    }
  },
  computed:{
    information(){
      return this.$store.state.information;
    }
  },
  onUnload(){
    var _this=this;
    var userToken=wx.getStorageSync('userToken')
    wx.request({
      url:'https://daka.rzkeji.com/api/ucenter/set-userinfo',
      data:{
        daka_token:userToken,
        photo_id:_this.information.returnId,
        nickname:_this.information.nickname,
        wx_num:_this.information.weChatNumber,
        sex:(parseInt(_this.information.index)+1),
        description:_this.information.sign,
        birthday:_this.information.birthDate
      },
      header:{
        "content-type":"application/json"
      },
      method:'POST',
      success(res){
         console.log(res.data.message)
      }
    })
  }
}
</script>
<style scoped>
.container{width: 100%;height: 100%}
li{width: 100%;height: 70px;line-height: 70px;padding-left: 5px;font-size: 16px;}
.headImg img.peopleImg{width: 50px;height: 50px;float: right;margin-top: 10px;border-radius: 50px;}
.title{float: left;display: block;width: 100px;height: 50px;line-height: 50px;margin-top: 10px;}
.rightName{height: 50px;display: block;float:right;line-height: 50px;margin-top: 10px;width: 150px;text-align:right;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;}
.goImg{width: 25px;height: 25px;float: right;margin-top: 12px;margin-right: 10px;}
.goHeadImg{margin-top: 26px;}
.goSign{margin-top: 23px}
.pikcker{height:50px;margin-left: 30px;float: right;margin-top: 10px;line-height: 50px;}
.picker{height:50px;color: black}
</style>
